/**
 * 扑克类叫分
 */
var _ = require('./../../FrameWork/we_underscore');
var TimeOutCtr = require('./../../FrameWork/Component/TimeOutCtr');
var EnumPkRoom = require('./../Enum/EnumPkRoom');
var ClientDelegate = require('./../../FrameWork/Delegate/ClientDelegate');
var ClientEveDelegate = require('./../../FrameWork/Delegate/ClientEveDelegate');
var ClientPkDelegateType = require('./../Delegate/ClientPkDelegateType');
var UtilGameObject = require('./../../FrameWork/Utils/UtilGameObject');
module.exports = cc.Class({
    extends: ClientDelegate,
    properties: {
        timeOutCtr: {
            default: null,
            type: TimeOutCtr,
            displayName: '倒计时组件'
        },
        prefabLb: {
            default: null,
            type: cc.Prefab,
            displayName: '文字预设'
        },
        nodeNoDouble: {
            default: null,
            type: cc.Node,
            displayName: '不加倍'
        },
        nodeDouble: {
            default: null,
            type: cc.Node,
            displayName: '加倍'
        }
    },
    onLoad() {
        this._super();
        this.addListerDelegate(ClientPkDelegateType.Clinet_selfShouDouble, this.doActive.bind(this));

        var posList = [{
            pos: this.nodeNoDouble,
            world: '不加倍'
        }, {
            pos: this.nodeDouble,
            world: '加 倍'
        }];
        _.each(posList, function(_info) {
            var lbCtr = UtilGameObject.getCtrByPrefabs(this.prefabLb, _info.pos);
            lbCtr.setFontSize(43);
            lbCtr.setPositionY(5);
            lbCtr.setText(_info.world);
            lbCtr.setOutlineWidth2(5);
        }.bind(this));

        this.iniTest();
        this.resetNet();
    },
    resetNet() {
        if (window.g_room) {
            var isDoubling = EnumPkRoom.DOUBLING == window.g_room.getRoomState() && window.g_room.getSelfDoubleValue() == -1;
            this.doActive(isDoubling);
            return;
        }
        this.doActive(false);
    },
    doActive(_isDoubling) {
        this.setActive(_isDoubling);
        if (_isDoubling) {
            this.open();
        } else {
            this.timeOutCtr.doClose();
        }
    },
    /***不加倍 */
    eveNoDouble() {
        this.doActive(false);
        if (!!window.g_room) {
            window.g_room.refreshDoubleInfo({
                seatIdx: window.g_room.getSelfSeatIdx(),
                double: 0
            });
        }
        ClientEveDelegate.doDataToLister(ClientPkDelegateType.Client_gamingBtn_noOut);
    },
    /**加倍 */
    eveDouble() {
        this.doActive(false);
        window.g_room.refreshDoubleInfo({
            seatIdx: window.g_room.getSelfSeatIdx(),
            double: 1
        });
        ClientEveDelegate.doDataToLister(ClientPkDelegateType.Client_gamingBtn_noOut);
    },
    /***开启倒计时加倍
     * _timeOut:倒计时时间单位（秒）默认不填10秒
     */
    open(_timeOut) {
        _timeOut = null == _timeOut ? 10 : _timeOut;
        this.timeOutCtr.startCountDown(_timeOut, this.eveNoDouble.bind(this));
    },
    iniTest() {
        // UtilGameObject.createDemoBtn([
        //     ['头像', function() {
        //             this.showHeadAll();
        //         }.bind(this) 
        //     ],
        // ]);
        // this.showHeadAll();
    }
});